<template>
	<!-- 商品显示组件-横向排列方式显示 -->
	<view :style="{marginBottom: `${newData.pageSpacing}rpx`}" class="bg-white">
		<view class="wrapper-list-goods">
			<view>
				<scroll-view class="scroll-view_x goods-detail" scroll-x style="width:auto;overflow:hidden;">
					<block v-for="(item, index) in goodsList" :key="index">
						<navigator hover-class="none" :url="'/pages/goods/goods-detail/index?id=' + item.spuId+ '&activityId=' + item.activityId"
							class="item shadow-warp flex goods-box radius">
							<view @tap="click">
								<view class="img-box">
									<view class="" style="position: relative;height: 100%;" v-if="item.prescription=='2'">
										<view class="flex flex-column-center"
											style="position: absolute;width: 100%;height:100%;z-index: 50;align-items: center;">
											<view class="" style="font-size: 24rpx;">处方药依法不展示包装</view>
											<view class="" style="font-size: 24rpx;">请在药师指导下使用</view>
										</view>									
										<image :src="item.picUrls[0] ? item.picUrls[0] : '/static/image/no_pic.png'" style="filter: blur(5rpx);">
										</image>
									</view>
									<image :src="item.picUrls[0] ? item.picUrls[0] : '/static/image/no_pic.png'" v-if="item.prescription!='2'">
									</image>
								</view>
								<view class="text-cut goods-name margin-top-sm text-sm padding-left-sm">{{item.spuName}}
								</view>
								<view class="margin-xs">
									<text class="text-price text-gray text-sm "
										style="text-decoration: line-through;margin-right: 10rpx;"
										v-if="parseFloat(item.oldPrice) > parseFloat(item.price)">{{item.oldPrice}}</text>
									<text class="text-price text-red text-bold">
										{{item.price}}</text>
								</view>
								<view class="cfBox" v-if="item.prescription=='2'">处方药</view>
								<view class="preBox" v-if="item.isPressell == 1">预约</view>
							</view>
						</navigator>
					</block>
					<navigator hover-class="none" :url="newData.pageUrl"
						class="items shadow-warp flex goods-box radius goods-more">
						更多<text class="cuIcon-right"></text>
					</navigator>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/utils/api'
	const app = getApp();
	export default {
		components: {},
		props: {
			value: {
				type: Object,
				default: function() {
					return {
						title: '商品甄选',
						titleColor: 'red',
						titleIcon: 'cuIcon-message',
						pageSpacing: 0,
						goodsList: []
					}
				}
			},
			activityId: {}
		},
		data() {
			return {
				theme: app.globalData.theme, //全局颜色变量
				newData: this.value,
				goodsList: []
			};
		},
		mounted() {
			this.getgoodsList()
		},
		methods: {
			click() {
				uni.$emit('newShopsList', '1')
			},
			jumpPage(page) {
				if (page) {
					uni.navigateTo({
						url: page
					});
				}
			},
			getgoodsList() {
				if (this.value.goodsList && this.value.goodsList.length > 0) {
					let goodsids = []
					this.value.goodsList.forEach(v => {
						goodsids.push(v.spuId)
					})
					const page = {
						activityId: this.activityId,
						goodsids: goodsids.toString()
					}
					api.getActiveGoodByid(page).then(res => {
						let data = res.data
						if (data.length > 0) {
							this.goodsList = data.filter(v=>{
								return v.status == 1
							})
						} else {
							this.goodsList = []
						}						
					})
				}			
			}
		}
	}
</script>

<style scoped lang="scss">
	.wrapper-list-goods {
		white-space: nowrap;
		padding: 0 30rpx 6rpx 30rpx;
	}

	.wrapper-list-goods .item {
		display: inline-block;
		width: 260rpx;
		height: auto;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-left: 10rpx;
		margin-right: 10rpx;
		border: 1rpx solid #eee;
		background-color: #fff;
	}

	.wrapper-list-goods .items {
		display: inline-block;
		width: 120;
		height: 380rpx;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-left: 10rpx;
		margin-right: 10rpx;
		border: 1rpx solid #eee;
	}

	.wrapper-list-goods .item:nth-last-child(1) {
		margin-right: 0;
	}

	.wrapper-list-goods .item .img-box {
		width: 100%;
		height: 260rpx;

	}

	.wrapper-list-goods .item .img-box image {
		width: 100%;
		height: 100%;
		border-radius: 5rpx 5rpx 0 0;
	}

	.goods-selection {
		margin-left: 0rpx !important;
		color: #666666;
	}

	.goods-more {
		margin-right: 0rpx !important;
		color: #666666;
	}

	.goods-box {
		width: 349rpx;
		height: 530rpx;
		background-color: #fff;
		overflow: hidden;
		margin-bottom: 20rpx;
		border-radius: 10rpx;
	}

	.goods-box .img-box {
		width: 100%;
		height: 349rpx;
		overflow: hidden;
	}

	.goods-box .img-box image {
		width: 100%;
		height: 349rpx;
	}

	.goods-detail {
		margin-top: -20rpx !important;
	}

	.goods-more {
		text-align: center;
		line-height: 380rpx;
		width: 130rpx;
		background: #ccc;
		color: #fff;
	}
	
	
	.cfBox {
		width: 100rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background-color: #00a6ba;
		position: absolute;
		left: 0;
		top: 0;
		color: white;
		border-radius: 10rpx;
	}
	
	.preBox {
		width: 260rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background-color: #F76164;
		position: absolute;
		left: 0;
		top: 220rpx;
		color: white;
		opacity: 0.8;
	}
</style>
